//
//  ZDGoodsInfoCell.m
//  ZDPension
//
//  Created by 刘甲奇 on 2017/6/15.
//  Copyright © 2017年 maker. All rights reserved.
//

#import "ZDGoodsInfoCell.h"
#import "UIImageView+WebCache.h"

@interface ZDGoodsInfoCell()
@property (weak, nonatomic) IBOutlet UIImageView *icon;
@property (weak, nonatomic) IBOutlet UILabel *goodsNameLabel;
@property (weak, nonatomic) IBOutlet UITextField *inputField;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *clickNumberLabel;
@property (weak, nonatomic) IBOutlet UILabel *serviceTypeLabel;
/**
 <#Description#>
 */
@property(nonatomic,strong)goodsNumberBlock block;

@end

@implementation ZDGoodsInfoCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
}
- (void)goodsNumberClick:(goodsNumberBlock)block
{
    _block = block;
}
- (void)setModel:(ZDGoodsDetailModel *)model
{
    [self.icon sd_setImageWithURL:[NSURL URLWithString:model.goods_image_url] placeholderImage:[UIImage imageNamed:@"zwt"]];
    self.goodsNameLabel.text = model.goods_name;
    self.priceLabel.text = model.goods_price;
    self.clickNumberLabel.text = [NSString stringWithFormat:@"浏览数: %@",model.goods_click];
    if ([model.door_service isEqualToString:@"1"])
    {
        self.serviceTypeLabel.text = @"消费方式: 上门服务;店内消费";
    }else{
        self.serviceTypeLabel.text = @"消费方式: 店内消费";

    }
}
- (IBAction)minusClick:(UIButton *)sender
{
    int num = [self.inputField.text intValue];
    if (num == 1) {
        [SVProgressHUD showInfoWithStatus:@"最少数量为 1"];
        return;
    }else
    {
        self.inputField.text = [NSString stringWithFormat:@"%d",--num];
    }
    _block(num);
}
- (IBAction)addClick:(UIButton *)sender
{
    int num = [self.inputField.text intValue];
    self.inputField.text = [NSString stringWithFormat:@"%d",++num];
    _block(num);
}
- (void)keyboardWillHide:(NSNotification *)notification
{
    int num = [self.inputField.text intValue];
    _block(num);
}
@end
